package com.isoft.demo.service.impl;/*
 *@ClassName: FindTransferSysServiceImpl
 *@Date: 2021/6/28
 *@Author:刘逸飞
 */

import com.isoft.demo.common.ResponseData;
import com.isoft.demo.dao.FindTransferSysDao;
import com.isoft.demo.entity.Orders;
import com.isoft.demo.entity.Transport;
import com.isoft.demo.service.FindTransferSysService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class FindTransferSysServiceImpl implements FindTransferSysService {

    @Resource
    private FindTransferSysDao dao;

    @Override
    public ResponseData findTranSys() {
        List<Transport> list= dao.findTranSys();
        ResponseData rs=new ResponseData();
        if (list !=null){
            rs.setCode(0);
            rs.setMsg("OK");
            rs.setData(list);
        }else {
            rs.setCode(1);
            rs.setMsg("Fault");
        }
        return rs;
    }

    @Override
    public ResponseData findById(int tid) {
        List<Transport> list = dao.findById(tid);
        ResponseData rs = new ResponseData();
        if(list != null){
            rs.setCode(0);
            rs.setMsg("ok");
            rs.setData(list);
        } else {
            rs.setCode(1);
            rs.setMsg("error");
        }
        return rs;
    }

    @Override
    public ResponseData findByDate(String sdate,String edate) {
        List<Transport> list = dao.findByDate(sdate,edate);
        ResponseData rs = new ResponseData();
        if(list != null){
            rs.setCode(0);
            rs.setMsg("ok");
            rs.setData(list);
        } else {
            rs.setCode(1);
            rs.setMsg("error");
        }
        return rs;
    }

    @Override
    public ResponseData findBy(int tid,String sdate,String edate) {
        List<Transport> list = dao.findBy(tid,sdate,edate);
        ResponseData rs = new ResponseData();
        if(list != null){
            rs.setCode(0);
            rs.setMsg("ok");
            rs.setData(list);
        } else {
            rs.setCode(1);
            rs.setMsg("error");
        }
        return rs;
    }

    @Override
    public ResponseData addTransport(Transport transport) {
        int m = dao.addTransport(transport);
        ResponseData rs = new ResponseData();
        if(m > 0){
            rs.setCode(0);
            rs.setMsg("ok");
            List<Transport>list = new ArrayList<>();
            list.add(transport);
            rs.setData(list);
        }else {
            rs.setCode(1);
            rs.setMsg("fail");
        }
        return rs;
    }
}
